package com.usian.admin.kafka.listenter;

import com.alibaba.fastjson.JSON;
import com.usian.admin.service.WemediaNewsAutoScanService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class WemediaNewsAutoListener {

    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;


    @KafkaListener(topics = {"wm.news.auto.scan.topic"})
    public void receiverMessage(ConsumerRecord<?,?> record){

        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);

        if(optional.isPresent()){
            Object newId = record.value();
            System.out.println("kafka自动审核 文章id ="+newId);
            wemediaNewsAutoScanService.autoScanByMediaNewsId(Integer.valueOf(newId.toString()));
            System.out.println("kafka自动审核完成");
        }

    }
}
